package com.roadjava.rbac.config;

import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.roadjava.rbac.config.properties.AuthorizationProperties;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
@EnableConfigurationProperties({AuthorizationProperties.class})
public class WebMvcConfig implements WebMvcConfigurer {
    /**
     * 定制化ObjectMapper
     */
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer objectMapperBuilderCustomizer() {
       return  jacksonObjectMapperBuilder -> {
           // Long类型序列化为字符串,避免精度丢失
           jacksonObjectMapperBuilder.serializerByType(Long.class, ToStringSerializer.instance);
           // long类型序列化为字符串,避免精度丢失
           jacksonObjectMapperBuilder.serializerByType(Long.TYPE, ToStringSerializer.instance);
       };
    }
}
